# -*- coding: utf-8 -*-
from openerp.osv import fields
from openerp.osv import osv
from openerp import SUPERUSER_ID
import datetime, time


class hr_expense_expense(osv.osv):
    _inherit = 'hr.expense.expense'

    def expense_canceled(self, cr, uid, ids, context=None):
        for expense_row in self.browse(cr, uid, ids, context=context):
            if expense_row.state == 'done':
                if expense_row.account_move_id and expense_row.account_move_id.state != 'draft':
                    expense_row.account_move_id.button_cancel()
                expense_row.account_move_id.unlink() if expense_row.account_move_id else False
        return self.write(cr, uid, ids, {'state': 'cancelled'}, context=context)

    def onchange_currency_id(self, cr, uid, ids, currency_id=False, company_id=False, context=None):
        return {}

    def default_get(self, cr, uid, fields_list, context=None):
        return_val = super(hr_expense_expense, self).default_get(cr, uid, fields_list, context=context)
        model_data_obj = self.pool.get('ir.model.data')
        journal_id = model_data_obj.xmlid_to_res_id(cr, SUPERUSER_ID, 'dftg_ext.dftg_fee_journal')
        return_val.update({'journal_id': journal_id})
        return return_val
